// 组合函数
const _ = require("loadsh")
const fp = require("loadsh/fp")

const toUpper = str => str.toUpperCase()
const reverse = arr => arr.reverse()
const first = arr => arr[0]

// const compose = _.flowRight(toUpper, first, reverse)
// const fn = compose(["f", "a"])
// console.log(fn)

// function compose(...fns) {
//     return function (val) {
//         return fns.reduce((prev, cur) => {
//             return cur(prev)
//         }, val)
//     }
// }

// const func = compose(reverse, first, toUpper)
// console.log(func(["ere", "ereqwb", "rrewc"]))

// // es6 
// const compose2 = (...fns) => (val) =>  fns.reduce((prev, cur) => cur(prev),val)
// const func2 = compose(reverse, compose2(first, toUpper))
// console.log("compose2", func2(["aew", "bewq", "frewr"]))

// const trace=_.curry((tag, v) => { 
//     console.log(tag, v) 
//     return v 
// })
// const split =_.curry((sep, str) =>_.split(str, sep)) 
// const join =_.curry((sep, array) =>_.join(array, sep)) 
// const map =_.curry((fn, array) =>_.map(array, fn))
// const f =_.flowRight(join('-'), trace('map 之后'), map(_.toLower), trace('split之后'), split(' '))
// console.log(f('GET ELEMENT BY ID'))

const fn = fp.flowRight(fp.join("-"), fp.map(fp.toLower), fp.split(" "))
console.log("fn", fn("DSFDS FDSFD FGDS"))